﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;

namespace ADC.BL
{
    public class ApplicationObjectFactory
    {
        public  const string USER_SESSION_COUNT="USER_SESSION_COUNT" ;
        public  const string USER_PAGE_VIEW_COUNT = "USER_PAGE_VIEW_COUNT";
        public const string MAX_USER_ONLINE = "MAX_USER_ONLINE";

        public static ApplicationObject getByName(String objectName)
        {
            var db = new dbADCEntities();
            return db.ApplicationObjects.Where(g => g.ApplicationObjectName == objectName).FirstOrDefault();
        }

        public static void Insert(ApplicationObject appObject)
        {
            var db = new dbADCEntities();
            db.AddToApplicationObjects(appObject);
            db.SaveChanges();
        }

        public static int Update(ApplicationObject appObject)
        {
            var db = new dbADCEntities();
            var updateAppObject = new ApplicationObject();
            updateAppObject = db.ApplicationObjects.Where(g => g.ApplicationObjectID == appObject.ApplicationObjectID).FirstOrDefault();
            updateAppObject.ApplicationObjectValueFloat = appObject.ApplicationObjectValueFloat;
            updateAppObject.ApplicationObjectValueLong = appObject.ApplicationObjectValueLong;
            updateAppObject.ApplicationObjectValueString = appObject.ApplicationObjectValueString;
            updateAppObject.ApplicationObjectValueDatetime = appObject.ApplicationObjectValueDatetime;
            return db.SaveChanges();
        }
    }
}
